<?php
namespace WMApi\Model;

use Think\Model;

/**
 * 购物车模型
 * 
 * @author ^2_3^
 */
class WmCartModel extends Model {
    
    /**
     * 购物车_清空
     * 
     * @param int $uid 用户ID;
     * @param int $store_id 店铺ID;
     * 
     * @author ^2_3^
     */
    public function cart_clean_up( $uid = 0, $store_id = 0 ) {
        if( empty($uid) || empty($store_id) ) {
            returnApiError('WmCartModel->cart_clean_up()参数缺失;');
        }
        
        $where = array(
            'uid' => $uid,
            'store_id' => $store_id
        );
        return $this->where( $where )->delete();
    }
    
    /**
     * 获取购物车商品列表
     * 
     * @param int uid 用户ID;
     * @param int store_id 店铺ID;
     * 
     * @author ^2_3^
     * *
     */
    public function get_goods_list($uid, $store_id) {
        if( empty($uid) || empty($store_id) ) {
            returnApiError('提示:get_goods_list参数错误;');
        }
        
        $where_c = array(
            "c.uid" => $uid,
            "c.store_id" => $store_id
        );
        
        $goods_list = $this->alias('c')
            ->field('
                    c.cart_id,
                	c.uid,
                	c.store_id,
                	c.goods_id,
                	c.goods_name,
                	c.sku_id,
                	c.market_price AS c_market_price,
                	c.goods_price AS c_goods_price,
                	c.goods_num,
                    g.goods_sn,
                	g.market_price AS g_now_market_price,
                	g.goods_price AS g_now_goods_price,
                	g.is_sku,
                	g.state,
                	g.is_del AS g_is_del,
                    gs.main_attr_name,
                    gs.main_attr_value_name,
                    gs.sec_attr_name,
                    gs.sec_attr_value_name,
                	gs.goods_money AS gs_now_goods_price,
                	gs.is_del AS gs_is_del
                ')
            ->join('sdx_wm_goods g ON g.goods_id = c.goods_id', 'left')
            ->join('sdx_wm_goods_sku gs ON gs.sku_id = c.sku_id', 'left')
            ->where($where_c)
            ->select();
// w_log('cyb_log', "WmCartModel > get_goods_list \r\n".$this->getLastSql());
        
        return $goods_list;
    }
    
}